Answer the following questions and complete the exercises in
RMarkdown. Please embed all of your code and push your final work to
your repository. Your final lab report should be organized, clean, and
run free from errors. Remember, you must remove the # for
the included code chunks to run. Be sure to add your name to the author
header above. For any included plots, make sure they are clearly
labeled. You are free to use any plot type that you feel best
communicates the results of your analysis.
Make sure to use the formatting conventions of RMarkdown to make your report neat and clean!
library(tidyverse)
library(janitor)
library(ggmap)
We will use two separate data sets for this homework.
The first data set represent sightings of grizzly bears (Ursos arctos) in Alaska.
The second data set is from Brandell, Ellen E (2021), Serological dataset and R code for: Patterns and processes of pathogen exposure in gray wolves across North America, Dryad, Dataset.
Load the grizzly data and evaluate its
structure.
grizzly<- read_csv("data/bear-sightings.csv")
## Rows: 494 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (3): bear.id, longitude, latitude
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
glimpse(grizzly)
## Rows: 494
## Columns: 3
## $ bear.id <dbl> 7, 57, 69, 75, 104, 108, 115, 116, 125, 135, 137, 162, 185, …
## $ longitude <dbl> -148.9560, -152.6228, -144.9374, -152.8485, -143.2948, -149.…
## $ latitude <dbl> 62.65822, 58.35064, 62.38227, 59.90122, 61.07311, 62.91605, …
grizzly %>%
select(latitude, longitude) %>%
summary()
## latitude longitude
## Min. :55.02 Min. :-166.2
## 1st Qu.:58.13 1st Qu.:-154.2
## Median :60.97 Median :-151.0
## Mean :61.41 Mean :-149.1
## 3rd Qu.:64.13 3rd Qu.:-145.6
## Max. :70.37 Max. :-131.3
grizzly_lat<- c(55.02, 70.37)
grizzly_long<- c(-166.2, -131.3)
grizzly_bbox<- make_bbox(grizzly_long, grizzly_lat, f=0.01)
stamen in a terrain style projection
and display the map.register_stadiamaps("96e39c85-6279-41e1-ab0b-bb6075741a9a", write=FALSE)
grizzly_map<-get_stadiamap(grizzly_bbox, maptype = "stamen_terrain", zoom=7)
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
## ℹ 182 tiles needed, this may take a while (try a smaller zoom?)
ggmap(grizzly_map)
ggmap(grizzly_map)+
geom_point(data= grizzly, aes(longitude, latitude), size=0.3)+
labs(x="Longitude", y="Latitude", title= "Grizzly Bear Observations in Alaska")
Let’s switch to the wolves data. Brandell, Ellen E (2021), Serological dataset and R code for: Patterns and processes of pathogen exposure in gray wolves across North America, Dryad, Dataset.
wolves<- read_csv("data/wolves_dataset.csv")
## Rows: 1986 Columns: 23
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): pop, age.cat, sex, color
## dbl (19): year, lat, long, habitat, human, pop.density, pack.size, standard....
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
glimpse(wolves)
## Rows: 1,986
## Columns: 23
## $ pop <chr> "AK.PEN", "AK.PEN", "AK.PEN", "AK.PEN", "AK.PEN", "…
## $ year <dbl> 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 200…
## $ age.cat <chr> "S", "S", "A", "S", "A", "A", "A", "P", "S", "P", "…
## $ sex <chr> "F", "M", "F", "M", "M", "M", "F", "M", "F", "M", "…
## $ color <chr> "G", "G", "G", "B", "B", "G", "G", "G", "G", "G", "…
## $ lat <dbl> 57.03983, 57.03983, 57.03983, 57.03983, 57.03983, 5…
## $ long <dbl> -157.8427, -157.8427, -157.8427, -157.8427, -157.84…
## $ habitat <dbl> 254.08, 254.08, 254.08, 254.08, 254.08, 254.08, 254…
## $ human <dbl> 10.42, 10.42, 10.42, 10.42, 10.42, 10.42, 10.42, 10…
## $ pop.density <dbl> 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, …
## $ pack.size <dbl> 8.78, 8.78, 8.78, 8.78, 8.78, 8.78, 8.78, 8.78, 8.7…
## $ standard.habitat <dbl> -1.6339, -1.6339, -1.6339, -1.6339, -1.6339, -1.633…
## $ standard.human <dbl> -0.9784, -0.9784, -0.9784, -0.9784, -0.9784, -0.978…
## $ standard.pop <dbl> -0.6827, -0.6827, -0.6827, -0.6827, -0.6827, -0.682…
## $ standard.packsize <dbl> 1.3157, 1.3157, 1.3157, 1.3157, 1.3157, 1.3157, 1.3…
## $ standard.latitude <dbl> 0.7214, 0.7214, 0.7214, 0.7214, 0.7214, 0.7214, 0.7…
## $ standard.longitude <dbl> -2.1441, -2.1441, -2.1441, -2.1441, -2.1441, -2.144…
## $ cav.binary <dbl> 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
## $ cdv.binary <dbl> 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ cpv.binary <dbl> 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, …
## $ chv.binary <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, …
## $ neo.binary <dbl> NA, NA, NA, 0, 0, NA, NA, 1, 0, 1, NA, 0, NA, NA, N…
## $ toxo.binary <dbl> NA, NA, NA, 1, 0, NA, NA, 1, 0, 0, NA, 0, NA, NA, N…
wolves %>%
count(pop) %>%
arrange(desc(n))
## # A tibble: 17 × 2
## pop n
## <chr> <int>
## 1 YNP 383
## 2 MT 351
## 3 MEXICAN 181
## 4 DENALI 154
## 5 BC 145
## 6 YUCH 105
## 7 MI 102
## 8 AK.PEN 100
## 9 BAN.JAS 96
## 10 SNF 92
## 11 N.NWT 67
## 12 GTNP 60
## 13 ONT 60
## 14 INT.AK 35
## 15 SS.NWT 34
## 16 ELLES 11
## 17 SE.AK 10
wolves_US48<-wolves %>%
filter(lat < 52.19775 & long < 117.05430)
wolves_US48
## # A tibble: 1,229 × 23
## pop year age.cat sex color lat long habitat human pop.density
## <chr> <dbl> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 GTNP 2012 P M G 43.8 -111. 10375. 3924. 34.0
## 2 GTNP 2012 P F G 43.8 -111. 10375. 3924. 34.0
## 3 GTNP 2012 P F G 43.8 -111. 10375. 3924. 34.0
## 4 GTNP 2012 P M B 43.8 -111. 10375. 3924. 34.0
## 5 GTNP 2013 A F G 43.8 -111. 10375. 3924. 34.0
## 6 GTNP 2013 A M G 43.8 -111. 10375. 3924. 34.0
## 7 GTNP 2013 P M G 43.8 -111. 10375. 3924. 34.0
## 8 GTNP 2013 P M G 43.8 -111. 10375. 3924. 34.0
## 9 GTNP 2013 P M G 43.8 -111. 10375. 3924. 34.0
## 10 GTNP 2013 P F G 43.8 -111. 10375. 3924. 34.0
## # ℹ 1,219 more rows
## # ℹ 13 more variables: pack.size <dbl>, standard.habitat <dbl>,
## # standard.human <dbl>, standard.pop <dbl>, standard.packsize <dbl>,
## # standard.latitude <dbl>, standard.longitude <dbl>, cav.binary <dbl>,
## # cdv.binary <dbl>, cpv.binary <dbl>, chv.binary <dbl>, neo.binary <dbl>,
## # toxo.binary <dbl>
wolves_US48 %>%
select(lat, long) %>%
summary()
## lat long
## Min. :33.89 Min. :-110.99
## 1st Qu.:44.60 1st Qu.:-110.99
## Median :44.60 Median :-110.55
## Mean :44.26 Mean :-105.88
## 3rd Qu.:46.83 3rd Qu.:-109.17
## Max. :50.24 Max. : -85.95
wolves_lat<-c(33.89, 50.24)
wolves_long<-c(-110.99, -85.95)
wolves_bbox<-make_bbox(wolves_long, wolves_lat, f=0.03)
stamen in a terrain-lines
projection and display the map.wolves_map<-get_stadiamap(wolves_bbox, maptype="stamen_terrain", zoom=7)
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
## ℹ 90 tiles needed, this may take a while (try a smaller zoom?)
ggmap(wolves_map)
ggmap(wolves_map)+
geom_point(data=wolves_US48, aes(long, lat), size=2, na.rm=T)+
labs(title="Wolves in 48 Lower States")
fill and color by population.ggmap(wolves_map)+
geom_point(data=wolves_US48, aes(x=long, y=lat, size=0.3, color=pop))+
labs(title="Wolves in 48 Lower States")
Please be sure that you check the keep md file in the
knit preferences.